import React, { Component } from 'react'
import { connect } from 'react-redux'
import {
    InputItem,
    Button,
    List,
    TextareaItem
} from 'antd-mobile'
import { update } from '../../redux/action'
import { createForm } from 'rc-form'
import  { Redirect } from 'react-router-dom'
import HeaderSelector from '../../compoments/header_selector/headerSelector'

class JobSeekerInfo extends Component{

    state = {
        header:'',
        port:'',
        info:''
    }

    saveInfo = () =>{
        this.props.form.validateFields((error,value)=>{
            this.setState(value,()=>{
                this.props.update(this.state)
            })
        })
    }
    getHeader = (header) =>{
        this.setState({
            header
        })
    }

    render() {
        let errors
        const { getFieldProps,getFieldError } = this.props.form;
        const { userType, header } = this.props.user
        if (header) {
            const path = userType === 'jobSeeker' ? '/jobSeeker' : '/boss'
            return <Redirect to={path} />
        }
        return(
            <div>
                <HeaderSelector getHeader={this.getHeader} />
                <List>
                    <InputItem
                        {...getFieldProps('port')}
                        placeholder='请输入求职岗位'
                    >求职岗位：</InputItem>
                    <TextareaItem
                        {...getFieldProps('info')}
                        title='个人简介：'
                        autoHeight
                    />
                    <Button type='primary' onClick={this.saveInfo}>保存</Button>
                    {(errors = getFieldError('required')) ? errors.join(',') : null}
                </List>
            </div>
        )
    }
}

export default connect(
    state=>({ user:state.user }),
    { update }
)(createForm()(JobSeekerInfo))